package com.dcivision.framework.web;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.bean.AbstractBaseObject;

public abstract class AbstractActionForm extends org.apache.struts.validator.ValidatorForm {
  protected Log log = new LogFactoryImpl().getInstance(this.getClass());
  protected final static String HIDDEN_DATETIME_FORMAT = SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT);

  /** Holds value of property opMode. */
  private String opMode;

  /** Holds value of property navMode. */
  private String navMode;

  /** Holds value of property ID. */
  private String ID;

  /** Holds value of property recordStatus. */
  private String recordStatus;

  /** Holds value of property updateCount. */
  private String updateCount;

  /** Holds value of property creatorID. */
  private String creatorID;

  /** Holds value of property createDate. */
  private String createDate;

  /** Holds value of property updaterID. */
  private String updaterID;

  /** Holds value of property updateDate. */
  private String updateDate;

  /** Holds value of property sortMode. */
  private String sortMode;

  /** Holds value of property sortAttribute. */
  private String sortAttribute;

  protected String returnTo = null;

  /** Creates a new instance of AbstractValidatorForm */
  public AbstractActionForm() {
    super();
  }

  /** Getter for property opMode.
   * @return Value of property opMode.
   */
  public String getOpMode() {
    return this.opMode;
  }

  /** Setter for property opMode.
   * @param opModes New value of property opMode.
   */
  public void setOpMode(String opMode) {
    this.opMode = opMode;
  }

  /** Getter for property navMode.
   * @return Value of property navMode.
   */
  public String getNavMode() {
    return this.navMode;
  }

  /** Setter for property navMode.
   * @param navModes New value of property navMode.
   */
  public void setNavMode(String navMode) {
    this.navMode = navMode;
  }

  /** Getter for property ID.
   * @return Value of property ID.
   */
  public String getID() {
    return this.ID;
  }

  /** Setter for property ID.
   * @param ID New value of property ID.
   */
  public void setID(String ID) {
    this.ID = ID;
  }

  /** Getter for property recordStatus.
   * @return Value of property recordStatus.
   */
  public String getRecordStatus() {
    return this.recordStatus;
  }

  /** Setter for property recordStatus.
   * @param recordStatus New value of property recordStatus.
   */
  public void setRecordStatus(String recordStatus) {
    this.recordStatus = recordStatus;
  }

  /** Getter for property updateCount.
   * @return Value of property updateCount.
   */
  public String getUpdateCount() {
    return this.updateCount;
  }

  /** Setter for property updateCount.
   * @param updateCount New value of property updateCount.
   */
  public void setUpdateCount(String updateCount) {
    this.updateCount = updateCount;
  }

  /** Getter for property creatorID.
   * @return Value of property creatorID.
   */
  public String getCreatorID() {
    return this.creatorID;
  }

  /** Setter for property creatorID.
   * @param creatorID New value of property creatorID.
   */
  public void setCreatorID(String creatorID) {
    this.creatorID = creatorID;
  }

  /** Getter for property createDate.
   * @return Value of property createDate.
   */
  public String getCreateDate() {
    return this.createDate;
  }

  /** Setter for property createDate.
   * @param createDate New value of property createDate.
   */
  public void setCreateDate(String createDate) {
    this.createDate = createDate;
  }

  /** Getter for property updaterID.
   * @return Value of property updaterID.
   */
  public String getUpdaterID() {
    return this.updaterID;
  }

  /** Setter for property updaterID.
   * @param updaterID New value of property updaterID.
   */
  public void setUpdaterID(String updaterID) {
    this.updaterID = updaterID;
  }

  /** Getter for property updateDate.
   * @return Value of property updateDate.
   */
  public String getUpdateDate() {
    return this.updateDate;
  }

  /** Setter for property updateDate.
   * @param updateDate New value of property updateDate.
   */
  public void setUpdateDate(String updateDate) {
    this.updateDate = updateDate;
  }

  /** Getter for property sortMode.
   * @return Value of property sortMode.
   */
  public String getSortMode() {
    return this.sortMode;
  }

  /** Setter for property sortMode.
   * @param sortMode New value of property sortMode.
   */
  public void setSortMode(String sortMode) {
    this.sortMode = sortMode;
  }

  /** Getter for property sortAttribute.
   * @return Value of property sortAttribute.
   */
  public String getSortAttribute() {
    return this.sortAttribute;
  }

  /** Setter for property sortAttribute.
   * @param sortAttribute New value of property sortAttribute.
   */
  public void setSortAttribute(String sortAttribute) {
    this.sortAttribute = sortAttribute;
  }

  /** Getter for property returnTo.
   * @return Value of property returnTo.
   */
  public String getReturnTo() {
    return this.returnTo;
  }

  /** Setter for property returnTo.
   * @param returnTo New value of property returnTo.
   */
  public void setReturnTo(String returnTo) {
    this.returnTo = returnTo;
  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    return null;
  }

  public void reset(ActionMapping mapping, HttpServletRequest request) {
    super.reset(mapping, request);
  }

  public String formatTimestamp(Timestamp inTime) {
    if (inTime==null) {
      return("");
    }

    String result = null;
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(HIDDEN_DATETIME_FORMAT, new java.util.Locale("en", "US"));
    result = sdf.format(inTime);
    return(result);
  }

  public Timestamp parseTimestamp(String inStr) {
    if (com.dcivision.framework.Utility.isEmpty(inStr)) {
      return(null);
    }
    java.util.Date tmpDate = null;
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(HIDDEN_DATETIME_FORMAT, new java.util.Locale("en", "US"));
    try {
      tmpDate = sdf.parse(inStr);
      return (new Timestamp(tmpDate.getTime()));
    } catch (java.text.ParseException pe) {
      log.error("Error when parsing a datetime string.", pe);
      return(null);
    }
  }

  public abstract void setFormData(AbstractBaseObject baseObj) throws ApplicationException;

  public abstract AbstractBaseObject getFormData() throws ApplicationException;
}
